//
//  DKOrderWarnCell.m
//  DanKU
//
//  Created by EDY on 2023/10/29.
//

#import "DKOrderWarnCell.h"
#import "DKUILabel+CustomText.h"
#import "DKUnauthorizedProductStepView.h"
#import "DKUnauthorizedProductStepView.h"
#import "OrderTool.h"

@interface DKOrderWarnCell()<DKUnauthorizedProductDelegate>


@property(nonatomic,strong)UIImageView *dk_WarnCellImg;
@property(nonatomic,strong)UILabel *dk_WarnCellcontentlab;
@property (nonatomic, strong)DKUnauthorizedProductStepView * dkUnauthorizedProductStepView;


@property(nonatomic,strong)UILabel *dk_totalbilleft;
@property(nonatomic,strong)UILabel *dk_totalbilRight;
@end


@implementation DKOrderWarnCell

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = DK_Hex(@"#FAFAFA");
        [self creatUI];
    }
    return self;
}



-(void)creatUI{
    UILabel *dk_welcomeLab = [[UILabel alloc] init];
    dk_welcomeLab.textColor = DK_Hex(@"#333333");
    dk_welcomeLab.font = DK_FONT_Semibold(30);
    dk_welcomeLab.text = @"Welcome！";
    [self addSubview:dk_welcomeLab];
    [dk_welcomeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(30);
        make.right.equalTo(self).offset(-30);
        make.height.mas_equalTo(50);
        make.top.equalTo((@(DK_IsWidthScale(62))));
    }];
    __weak __typeof(self)weakSelf = self;
    self.dkUnauthorizedProductStepView = [[DKUnauthorizedProductStepView alloc] init];
    self.dkUnauthorizedProductStepView.delagate = self;
    [self addSubview:self.dkUnauthorizedProductStepView];
    [self.dkUnauthorizedProductStepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.top.equalTo(dk_welcomeLab.mas_bottom).offset(DK_IsWidthScale(19));
        make.height.equalTo(@(DK_IsWidthScale(52)));
    }];
    
    [self addSubview:self.dk_WarnCellView];
    [self.dk_WarnCellView addSubview:self.dk_WarnCellImg];
    [self.dk_WarnCellView addSubview:self.dk_WarnCellcontentlab];
    [self.dk_WarnCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.right.equalTo(self).offset(-10);
        make.top.equalTo(self.dkUnauthorizedProductStepView.mas_bottom).offset(15);
        make.height.mas_equalTo(100);
    }];
    
    [self.dk_WarnCellImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_WarnCellView).offset(10);
        make.top.equalTo(self.dk_WarnCellView).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(14);
    }];
    
    [self.dk_WarnCellcontentlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dk_WarnCellView).offset(5);
        make.left.equalTo(self.dk_WarnCellImg.mas_right).offset(8);
        make.right.equalTo(self.dk_WarnCellView).offset(-10);
        make.bottom.equalTo(self.dk_WarnCellView).offset(-5);
        
    }];
    
    
    [self addSubview:self.dk_totalbilview];
    [self.dk_totalbilview addSubview:self.dk_totalbilleft];
    [self.dk_totalbilview addSubview:self.dk_totalbilRight];
    
    [self.dk_totalbilview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(20);
        make.right.equalTo(self).offset(-20);
        make.top.equalTo(self.dk_WarnCellView.mas_bottom).offset(10);
        make.bottom.equalTo(self);
    }];
    
    [self.dk_totalbilleft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.dk_totalbilview);
        make.width.mas_equalTo(DK_SCREEN_W/3);
    }];
    
    [self.dk_totalbilRight mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(self.dk_totalbilview);
        make.width.mas_equalTo(DK_SCREEN_W/3);
    }];
    
    DKUserBaseInfoModel *dk_UserBaseInfoMdl = [DKGlobalHelper defaultManager].userBaseInfoMdl;
    self.dk_totalbilRight.text =  [NSString stringWithFormat:@"-%@",[OrderTool formatAmountForIndia:dk_UserBaseInfoMdl.repaymentTotalAmount]];
}

-(void)setType:(NSInteger)Type{
    _Type = Type;
    self.dkUnauthorizedProductStepView.Type = self.Type;
}

#pragma mark - 懒加载
-(UIView*)dk_WarnCellView{
    if (!_dk_WarnCellView) {
        _dk_WarnCellView = [[UIView alloc]init];
        _dk_WarnCellView.backgroundColor = DK_HexA(@"#FF0000", 0.05);
        _dk_WarnCellView.layer.cornerRadius = 10;
    }
    return _dk_WarnCellView;
}

- (UIImageView*)dk_WarnCellImg{
    if (!_dk_WarnCellImg) {
        _dk_WarnCellImg = [[UIImageView alloc] init];
        _dk_WarnCellImg.image =  DK_GetImage(@"dk_warning_red");
    }
    return _dk_WarnCellImg;
}

- (UILabel *)dk_WarnCellcontentlab {
    if (!_dk_WarnCellcontentlab) {
        _dk_WarnCellcontentlab = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        _dk_WarnCellcontentlab.textColor = DK_Hex(@"#333333");
        _dk_WarnCellcontentlab.font = [UIFont systemFontOfSize:12];
        _dk_WarnCellcontentlab.numberOfLines = 0;
//        _dk_WarnCellcontentlab.text = @"1.Please repay separately when applying for multiple products\n2.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n3.After the transfer, please make sure to return to the app and paste Ref/UTR";
//        [_dk_WarnCellcontentlab addColoredText:@"latest UPI" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
//        [_dk_WarnCellcontentlab addColoredText:@"paste Ref/UTR" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
        
        NSString *loanHead = @"1.Please repay separately when applying for multiple products\n2.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n3.After the transfer, please make sure to return to the app and paste Ref/UTR";
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:loanHead];
        [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#333333") range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(133,10)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(loanHead.length-7,7)];
        _dk_WarnCellcontentlab.attributedText = attStr;
    }
    return _dk_WarnCellcontentlab;
}


-(UIView*)dk_totalbilview{
    if (!_dk_totalbilview) {
        _dk_totalbilview = [[UIView alloc]init];
        _dk_totalbilview.hidden = YES;
    }
    return _dk_totalbilview;
}

- (UILabel *)dk_totalbilleft {
    if (!_dk_totalbilleft) {
        _dk_totalbilleft = [[UILabel alloc] init];
        _dk_totalbilleft.textColor = DK_Hex(@"#333333");
        _dk_totalbilleft.font = [UIFont boldSystemFontOfSize:16];
        _dk_totalbilleft.text = @"Total Bills";
    }
    return _dk_totalbilleft;
}

- (UILabel *)dk_totalbilRight {
    if (!_dk_totalbilRight) {
        _dk_totalbilRight = [[UILabel alloc] init];
        _dk_totalbilRight.textColor = DK_Hex(@"#333333");
        _dk_totalbilRight.font = [UIFont systemFontOfSize:20];
        _dk_totalbilRight.text = @"-₹ 10,000";
        _dk_totalbilRight.textAlignment = 2;
    }
    return _dk_totalbilRight;
}


#pragma mark DKUnauthorizedProductDelegate

-(void)DKUnauthorizedProductSelectedIndex:(NSInteger)index{
    if ([self.delegate respondsToSelector:@selector(DKOrderWarnSelectedDelegate:)]) {
        [self.delegate DKOrderWarnSelectedDelegate:index];
    }
}

@end





